<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="shortcut icon" href="./favicon.ico" />
    <link rel="stylesheet" href="./css/zhuche.css">
</head>

<body>
    <header>
        <img src="./images/l.jpg" alt="">
        <ul class="banxin wnqcf">
            <li><a href="./index.html">联想首页</a></li>
            <li><a href="lianbiao.html">商城</a></li>
            <li><a href="gouwuche.html">购物车</a></li>
            <li><a href="lianbiao.html">服务</a></li>
            <li><a href="lianbiao.html">会员</a></li>
            <li><a href="lianbiao.html">社区</a></li>
            <li><a href="lianbiao.html">门店</a></li>
            <li><a href="lianbiao.html">品牌</a></li>
            <li><a href="" style="color: red;">下载app</a> </li>
            <li style="float: right;">
                <div class="headr_right .wnqcf">
                    <div class="zuo"><a href="./denlu.html">登录</a></div>
                    <div class="zhon">|</div>
                    <div class="you"><a href="./zhuche.html">注册</a></div>
                    <img src="./images/小手机.png" alt="">

                </div>
            </li>
        </ul>
    </header>
    <div class="zhuti">
        <form action="">
            <div class="biaoyu">注册会员</div>
            <input type="text" class="shouji" name="username" placeholder="输入账号号">
            <input type="password" name="password" placeholder="密码由8-20位字母、数字和符号组合" class="password">
            <input type="password" name="repassord" placeholder="确认密码" class="password">
            <button type="button" class="btn">立即注册</button>
            <a href="" class="denlu">已有账号，点此登录></a>
        </form>
    </div>

</body>
<script src="./node_modules/jquery/dist/jquery.js"></script>
<script src="./node_modules/layui-layer/dist/layer.js"></script>

<script>
    var button = document.querySelector('button')
    var usernameInput = document.querySelector('[name="username"]')
    var passwordInput = document.querySelector('[name="password"]')
    var repassInput = document.querySelector('[name="repassord"]')

    button.onclick = function(){
       
        // 验证用户名
        var reg = /^[a-zA-Z0-9]{5,10}$/;
        if (!reg.test(usernameInput.value)) {
            alert('用户名不符合规则')
            return false
        }
        // 验证密码：是否同时包含数字字母，6~16位
        // 是否同时包含了种
        if (!/[0-9]{5,15}/.test(passwordInput.value) || !/[a-zA-Z]+/.test(passwordInput.value)) {
            alert("密码不符合规范")
            return false;
        } 
        // 验证确认密码
        if (repassInput.value !== passwordInput.value) {
            alert('两次密码不一致')
            return false;
        }


        // $('.btn').click(function () {
        $(this).prop('disabled', 'true')
        // 加载弹出层
        var loadindex = layer.load(1, {
            shade: [0.3, '#000']
        })

        $.post('./php/zhuche.php', $('form').serialize(), res => {
            // console.log(res);
            var { meta: { status, msg } } = res;
            layer.close(loadindex)
            if (status === 2) {
                layer.msg(msg, {
                    icon: 1,
                    time: 1000
                }, function () {
                    location.href = "denlu.html"
                })

            } else {
                $(this).prop('disabled', false)
                layer.msg(msg, {
                    icon: 2,
                    time: 1000
                })
            }
        }, 'json')
    // })
    }



  
</script>

</html>